/**
 * 获取公司信息
 */
function getNationData(taxType) {
  const companyData = JSON.parse(window.localStorage.getItem('companyInfo'));
  let institutionCode =
    companyData.companyInfo.institutionCode === '1' ? '2007' : '2013';

  // eslint-disable-next-line no-shadow
  let taxInfo = {
    institution: institutionCode, // 国税对应制度 2007 | 2013
    nsrsbh: 'test', // 纳税人申报号
    nsrmc: 'test', // 纳税人名称（纳税公司）
    skssqq: '', // 税款所属期起
    skssqz: '', // 税款所属期止
    isZip: false,
    isHsqjSmall: false, // 是否为小微企业汇算清缴,
    saasInstitution: '',
  };
  taxInfo.isHsqjSmall = institutionCode === '2013';

  if (taxType === 'sds' || taxType === 'zzs') {
    window.postMessage(
      {
        event: 'backNationData',
        data: {
          taxInfo: taxInfo,
        },
      },
      '*'
    );
    return;
  }
  if (taxType === 'hsqj') {
    window.postMessage(
      {
        event: 'backNationData',
        data: {
          taxInfo: taxInfo,
        },
      },
      '*'
    );
    return true;
  }
  if (['balance', 'profit', 'cash'].includes(taxType) !== -1) {
    const cbzd = document.querySelector('.table-title').innerText;
    let saasInstitution = '';
    if (cbzd.includes('小企业')) {
      saasInstitution = 2;
    } else if (cbzd.includes('企业')) {
      saasInstitution = 1;
    } else {
      saasInstitution = '';
    }
    taxInfo.saasInstitution = saasInstitution;
    window.postMessage(
      {
        event: 'backNationData',
        data: {
          taxInfo: taxInfo,
        },
      },
      '*'
    );
  }
}

function changeInputData(el, value) {
  let copySetValue = Object.getOwnPropertyDescriptor(
    window.HTMLInputElement.prototype,
    'value'
  ).set;
  copySetValue.call(el, value);
  let e = new Event('input', { bubbles: true });
  el.dispatchEvent(e);
}

export { getNationData, changeInputData };
